package com.activeMq.persistence;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class Consumer {
    public static void main(String[] args) throws JMSException {
        ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue = session.createQueue("tx_queue");
        MessageConsumer consumer = session.createConsumer(queue);
        for (int i = 0; i <10 ; i++) {
            TextMessage message = (TextMessage) consumer.receive();
            String text = message.getText();
            System.out.println(text);
            if (i==3)
            message.acknowledge();
        }

        consumer.close();
        session.close();
        connection.close();
    }
}
